<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>考核申请</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/iconfont.css">
    <link rel="stylesheet" href="../lib/layui/css/layui.css" media="all">

    <link rel="stylesheet" href="../css/xadmin.css">
    <script src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <script src="../js/base.js"></script>
    <script src="../js/jquery.min.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        tr td,
        tr th {
            text-align: center !important;
            border: none !important;
        }

        tr td {
            border-bottom: 1px solid #eee !important;
            border-top: 1px solid #eee !important;
        }

        .shaixuan .layui-col-md12 .layui-inline {
            margin: 0;
        }

        .shaixuan .layui-col-md12 .layui-inline.layui-col-md4 .layui-form-label {
            width: 30%;
            padding-left: 0;
        }

        .shaixuan .layui-col-md12 .layui-inline.layui-col-md4 .layui-input-inline {
            width: 53%;
        }

        .shaixuan .layui-col-md12 .layui-inline.layui-col-md4 {
            margin-bottom: 20px;
        }

        .shaixuan .layui-col-md12 .layui-inline.layui-col-md3 .layui-form-label {
            width: 30%;
            padding-left: 0;
        }

        .shaixuan .layui-col-md12 .layui-inline.layui-col-md3 .layui-input-inline {
            width: 90%;
        }

        .shaixuan .layui-col-md12 .layui-inline.layui-col-md3 {
            margin-bottom: 20px;
        }

        .shaixuan .layui-col-md12 .layui-inline.layui-col-md6 .layui-form-label {
            width: 30%;
            padding-left: 0;
        }

        .shaixuan .layui-col-md12 .layui-inline.layui-col-md6 .layui-input-inline {
            width: 53%;
        }

        .shaixuan .layui-col-md12 .layui-inline.layui-col-md6 {
            margin-bottom: 20px;
        }

        .layui-table td,
        .layui-table th {
            min-width: 0px !important;
        }
    </style>
</head>

<body>
    <div class="layui-fluid" id="All_List">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card" style="display: flex;justify-content: space-between;">
                    <div class="layui-card-body ">
                        <blockquote class="layui-elem-quote" style="border:0;font-size: 18px;color: #000;">编辑球员资料
                        </blockquote>
                    </div>
                </div>
            </div>

            <div class="layui-col-md12 shaixuan">

                <div class="layui-card">
                    <div class="layui-fluid">
                        <div class="layui-row layui-col-space15">
                            <div class="layui-col-md10">
                                <div class="layui-card-body " style="display: flex;justify-content:space-between">
                                    <form class="layui-form" action="" style="width: 100%;">
                                        <div class="layui-form-item layui-col-md12">
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span class="x-red">*</span>姓名：</label>
                                                <div class="layui-input-inline">
                                                    <input data-id type="text" name="name" id="name" autocomplete="off"
                                                        class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span class="x-red">*</span>性别：</label>
                                                <div class="layui-input-inline">
                                                    <select id="sex" name="sex">
                                                        <option value="1">男</option>
                                                        <option value="2">女</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span
                                                        class="x-red">*</span>证件类型：</label>
                                                <div class="layui-input-inline">
                                                    <select id="documentType" name="documentType">
                                                        <option value="1">身份证</option>
                                                        <option value="2">护照</option>
                                                        <option value="3">户口本</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span
                                                        class="x-red">*</span>证件号码：</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="documentNumber" id="documentNumber"
                                                        autocomplete="off" class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span class="x-red">*</span>等级：</label>
                                                <div class="layui-input-inline" id="level" style="line-height: 38px;">
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span class="x-red">*</span>身高：</label>
                                                <div class="layui-input-inline">
                                                    <input maxlength="5" type="text" name="height" id="height"
                                                        autocomplete="off" class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span class="x-red">*</span>体重：</label>
                                                <div class="layui-input-inline">
                                                    <input maxlength="5" type="text" name="weight" id="weight"
                                                        autocomplete="off" class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span class="x-red">*</span>血型：</label>
                                                <div class="layui-input-inline">
                                                    <select id="bloodType" name="bloodType">
                                                        <option value="1">A</option>
                                                        <option value="2">B</option>
                                                        <option value="3">AB</option>
                                                        <option value="4">O</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span class="x-red">*</span>出生地：</label>
                                                <div class="layui-input-inline">
                                                    <input id="birthAddress" type="text" name="birthAddress"
                                                        autocomplete="off" class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span class="x-red">*</span>民族：</label>
                                                <div class="layui-input-inline">
                                                    <input id="nation" type="text" name="nation" autocomplete="off"
                                                        class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span
                                                        class="x-red">*</span>所属球队：</label>
                                                <div class="layui-input-inline" id="teamName"
                                                    style="line-height: 38px;">
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span
                                                        class="x-red">*</span>出生日期：</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="birthDay" id="birthDay" autocomplete="off"
                                                        class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span
                                                        class="x-red">*</span>教育程度：</label>
                                                <div class="layui-input-inline">
                                                    <select id="politicCountenance" name="politicCountenance">
                                                        <option value="1">小学</option>
                                                        <option value="2">初中</option>
                                                        <option value="3">中专</option>
                                                        <option value="4">高中</option>
                                                        <option value="5">大专</option>
                                                        <option value="6">本科</option>
                                                        <option value="7">研究生</option>
                                                        <option value="8">博士</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span
                                                        class="x-red">*</span>体检日期：</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="medicalReportDate" id="medicalReportDate"
                                                        autocomplete="off" class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span
                                                        class="x-red">*</span>电子邮箱：</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" id="email" name="email" autocomplete="off"
                                                        class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span
                                                        class="x-red">*</span>联系方式：</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" id="tel" name="tel" autocomplete="off"
                                                        class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md4">
                                                <label class="layui-form-label"><span
                                                        class="x-red">*</span>账户状态：</label>
                                                <div class="layui-input-inline">
                                                    <select id="isHidden" name="isHidden">
                                                        <option value="0">正常</option>
                                                        <option value="1">停用</option>
                                                    </select>
                                                </div>
                                            </div>

                                        </div>
                                        <div class="layui-form-item" style="text-align: center;display: none;">
                                            <button type="button" class="layui-btn submit" lay-submit
                                                lay-filter="submit">保存
                                            </button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                            <div class="layui-col-md2">
                                <div style="border: 1px solid #ccc;width: 115px;height: 137px;">
                                    <img id="updateHeadImg" src="" alt=""
                                        style="width:100%;height:100%;position:relative;top:50%;left:50%;margin-top:-69px;margin-left:-58px">
                                </div>
                                <button type="button" class="layui-btn" id="uploadHeadImg"
                                    style="width: 114px;height: 33px;border-radius:5px;margin-top: 15px;margin-left: 2px;">
                                    上传图片
                                </button>
                                <div style="width: 114px;margin-top: 10px;">只能上传gif/jpg/png/bmp文件，且不超过5M</div>
                            </div>
                            <div class="layui-form-item" style="text-align: center">
                                <button type="button" class="layui-btn" onclick="$('.layui-btn.submit').click()">保存
                                </button>
                                <button type="button" class="layui-btn transfer" onclick="">转会</button>
                            </div>

                        </div>
                    </div>
                </div>


            </div>
        </div>
    </div>
</body>

</html>

<script>
    var headPhoto, valId


    function child(id) {
        valId = id;
        layui.use(['table', 'laydate', 'upload'], function () {
            var table = layui.table;
            var laydate = layui.laydate;
            var upload = layui.upload;
            var form = layui.form;

            laydate.render({ //初始化时间选择
                elem: '#medicalReportDate'
            });
            laydate.render({ //初始化时间选择
                elem: '#birthDay'
            });

            //普通图片上传
            //上传头像
            var uploadInst = upload.render({
                elem: '#uploadHeadImg',
                url: uploadPlayerImg,
                exts: 'gif|jpg|png|bmp', //只允许上传后缀
                size: 5120,
                before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#updateHeadImg').attr('src', result); //图片链接（base64）
                    });
                },
                done: function (res) {
                    headPhoto = res.url
                    console.log(headPhoto)
                    //如果上传成功
                    if (res.msg == '0') {
                        layer.alert("上传成功")
                    }
                    //上传成功
                },
                error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html(
                        '<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>'
                    );
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            //普通图片上传


            form.on('submit(submit)', function (data) {

                var birthDay, teamName, nation, documentNumber, documentType, sex, heightEducation,
                    weight, bloodType, name, birthAddress, tel, email, height,
                    medicalReportDate, isHidden;
                birthDay = data.field.birthDay;
                teamName = data.field.teamName;
                nation = data.field.nation;
                documentNumber = data.field.documentNumber;
                documentType = data.field.documentType;
                sex = data.field.sex;
                heightEducation = data.field.heightEducation;
                weight = data.field.weight;
                bloodType = data.field.bloodType;
                name = data.field.name;
                birthAddress = data.field.birthAddress;
                tel = data.field.tel;
                email = data.field.email;
                height = data.field.height;
                medicalReportDate = data.field.medicalReportDate;
                isHidden = data.field.isHidden;
                if (name == "") {
                    layer.alert("请输入姓名", {
                        title: "提示"
                    });
                    return false
                } else if (documentNumber == "") {
                    layer.alert("请输入证件号码", {
                        title: "提示"
                    });
                    return false
                } else if (height == "") {
                    layer.alert("请输入正确的身高", {
                        title: "提示"
                    });
                    return false
                } else if (weight == "") {
                    layer.alert("请输入正确的体重", {
                        title: "提示"
                    });
                    return false
                } else if (nation == "") {
                    layer.alert("请输入正确的民族", {
                        title: "提示"
                    });
                    return false
                } else if (headPhoto == "") {
                    layer.alert("请选择头像", {
                        title: "提示"
                    });
                    return false
                } else if (birthAddress == "") {
                    layer.alert("请输入正确的出生地", {
                        title: "提示"
                    });
                    return false
                } else if (birthDay == "") {
                    layer.alert("请输入正确的出生日期", {
                        title: "提示"
                    });
                    return false
                } else if (medicalReportDate == "") {
                    layer.alert("请输入正确的体检日期 ", {
                        title: "提示"
                    });
                    return false
                } else if (email == "") {
                    layer.alert("请输入正确的邮箱 ", {
                        title: "提示"
                    });
                    return false
                } else if (!(/^1[3456789]\d{9}$/.test(tel))) {
                    layer.alert("请输入正确的手机号", {
                        title: "提示"
                    });
                    return false
                }

                $.ajax({
                    url: updatePlayerById,
                    type: 'post',
                    data: {
                        id: valId,
                        birthDay: birthDay,
                        teamName: teamName,
                        nation: nation,
                        documentNumber: documentNumber,
                        documentType: documentType,
                        sex: sex,
                        heightEducation: heightEducation,
                        weight: weight,
                        headPhoto: headPhoto,
                        bloodType: bloodType,
                        name: name,
                        birthAddress: birthAddress,
                        tel: tel,
                        email: email,
                        height: height,
                        medicalReportDate: medicalReportDate,
                        isHidden: isHidden,
                    },
                    dataType: 'json',
                    success: function (data) {
                        console.log(data)
                        if (data.msg == 0) {
                            var index1 = parent.layer.getFrameIndex(window
                                .name); //先得到当前iframe层的索引
                            layer.alert("保存成功", {
                                title: '提示',
                                cancel: function (index, layero) {
                                    parent.layui.table.reload("testReload")
                                    parent.layer.close(index1); //再执行关闭   
                                    layer.close(index)
                                }
                            }, function () {
                                parent.layui.table.reload("testReload")
                                parent.layer.close(index1); //再执行关闭   
                            })

                        } else {
                            layer.alert(data.msg, {
                                title: '提示'
                            })
                        }
                    },
                    error: function (data) {
                        console.log(data)
                        layer.alert(data.msg, {
                            title: '提示'
                        })
                    }
                });
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
            //实例
            $.ajax({
                url: findPlayerById,
                type: 'get',
                data: {
                    id: valId
                },
                dataType: 'json',
                success: function (data) {
                    console.log(data)
                    if (data.msg == 0) {
                        $("#teamName").text(data.user.teamName);
                        $("#teamName").attr("data-val", data.user.teamId);
                        $("#birthDay").val(data.user.birthDay);
                        $("#nation").val(data.user.nation);
                        $("#documentNumber").val(data.user.documentNumber);
                        $("#documentType").val(data.user.documentType);
                        $("#level").text(data.user.level + "级");
                        $("#sex").val(data.user.sex);
                        $("#heightEducation").val(data.user.heightEducation);
                        $("#weight").val(data.user.weight);
                        $("#updateHeadImg").attr("src", data.user.headPhoto);
                        // $("#nationality").val(data.user.nationality)  ;
                        $("#bloodType").val(data.user.bloodType);
                        $("#name").val(data.user.name);
                        $("#birthAddress").val(data.user.birthAddress);
                        $("#tel").val(data.user.tel);
                        $("#email").val(data.user.email);
                        $("#height").val(data.user.height);
                        $("#medicalReportDate").val(data.user.medicalReportDate);
                        $("#isHidden").val(data.user.isHidden);
                        headPhoto = $("#updateHeadImg").attr("src");
                        form.render()
                    } else {
                        layer.alert(data.msg, {
                            title: '提示'
                        })
                    }
                },
                error: function (data) {
                    console.log(data)
                    layer.alert(data.msg, {
                        title: '提示'
                    })
                }
            });

        })
    };
    $(".transfer").on("click", function () {
        layer.open({
            content: "transfer.html",
            type: 2, //打开的窗口的类型
            area: ["50%", "80%"],
            title: "球员转会",
            shadeClose: true,
            success: function (layero, index) {
                // console.log(data)//获取点击行的数据,获取打开的iframe
                var body = layer.getChildFrame('body', index);
                body.find("#name").text($("#name").val());
                body.find("#name").attr("data-val", valId);
                console.log($("#teamName").text())
                body.find("#you").text($("#teamName").text());
                body.find("#you").attr("data-val", $("#teamName").attr("data-val"));
            }
        })
    })
</script>
